class UserNotifier < ActionMailer::Base
  def signup_notification(user)
    setup_email(user)
    @subject    += '你的您这儿帐号已经启用'
    @body[:url]  = "http://www.ninzher.com/users/activate/#{user.activation_code}" 
  end
  
  def activation(user)
    setup_email(user)
    @subject    += '你的帐号已经被激活!'
    @body[:url]  = "http://www.ninzher.com/users/login"
  end
  
  protected
  def setup_email(user)
    @recipients  = "#{user.email}"
    @from        = "no-reply@ninzher.com"
    @subject     = "您这儿："
    @sent_on     = Time.now
    @body[:user] = user
  end
  
  def setup_invite_email(user, folk)
    @recipients  = "#{folk}"
    @from        = "no-reply@ninzher.com"
    @subject     = "[http://www.ninzher.com/] "
    @sent_on     = Time.now
    @body[:user] = user
  end
  
  def forgot_password(user)
    setup_email(user)
    @subject    += '修改你的密码'
    @body[:url]  = "http://www.ninzher.com/users/reset_password/#{user.password_reset_code}" 
  end

  def reset_password(user)
    setup_email(user)
    @subject += '你的密码已经被重置。'
  end
  
  def new_message(user, user_message)
    setup_email(user)
    @subject    += '你有了新的站内邮件'
    @body[:url]  = "http://www.ninzher.com/messages/#{user_message.message_id}" 
  end
  
  def new_friendship(user, friend)
    setup_email(friend)
    @subject    += "#{user.display_name}把你加为好友了"
    @body[:friend]  = user.display_name
    @body[:url]  = "http://www.ninzher.com/users/#{user.login}" 
  end
  
  def invite_folk(user, folk, content, invitation_code)
    setup_invite_email(user, folk)
    @subject    += "你的好友#{user.login}邀请你加入您这儿!"
    @body[:content] = content
    @body[:invitation_code] = invitation_code
    @body[:invite_url]  = "http://www.ninzher.com/users/check_invite/#{invitation_code}" 
    @body[:user_url]  = "http://www.ninzher.com/users/#{user.login}" 
  end

end
